#include "uart_cfg.h"
START_DEFINE_QUEUE(UartTX, UART_TX_BUFFER_SIZE, uint8_t, uint8_t)

START_DEFINE_QUEUE(UartRX, UART_RX_BUFFER_SIZE, uint8_t, uint8_t)

void UARTIntInit(void) 
{
    SPBRG = SPBRG_VAL;
    BRGH = BRGH_VAL;
    TRISC6 = 0;
    TRISC7 = 1;
    TXEN = 1;
    CREN = 1;
    SPEN = 1;
    TXIE = 1;
    RCIE = 1;
    GIE = 1;
    PEIE = 1;

}                

void UartISR(void)
{
    uint8_t chtemp;
    if(TXIF & TXIE)
    {
        if(GET_QUEUE_COUNT(UartTX)) {
            GET_QUEUE_DATA(UartTX, &chtemp);
            TXREG = chtemp;
        }
        else{
            TXIE = 0;
        }
    }
    if( RCIF & RCIE)
    {
        if(GET_QUEUE_COUNT(UartRX) != UART_RX_BUFFER_SIZE) {
                ADD_QUEUE_DATA(UartRX, RCREG);
        }
        //PIE1_bits.RCIE = 0;
    }
}
